package tr.com.netgis.web;

import tr.com.netgis.NGApplication;
import tr.com.netgis.SharedPrefs;

public class LoginRequest {

	private String userName;
	private String password;
	private String serverUrl;
	private ILoginRequestHandler handler;
	private boolean showFailureNotification = true;
	private boolean sharedSessionIdWillBeUpdated = true;

	public LoginRequest (){
		this.handler = new ILoginRequestHandler() {
			@Override
			public void call(LoginResponse response) {
				if (response.hasSession()) {
					if (sharedSessionIdWillBeUpdated)
						SharedPrefs.getInstance().setSessionId(response.getSessionId());					
				} else {
					if (showFailureNotification)
						NGApplication.showNotification("Oturum geçersiz", "Geçerli oturum için Ayarları kullanın.");
				}
			}
		};
	}
	
	/**
	 * if true a login failure notification will be shown incase of failure.
	 * @return
	 */
	public boolean isShowFailureNotification() {
		return showFailureNotification;
	}

	/**
	 * if true a login failure notification will be shown incase of failure.
	 * @param showNotification
	 */
	public void setShowFailureNotification(boolean showNotification) {
		this.showFailureNotification = showNotification;
	}

	/**
	 * if true session id which gathered after web service call, will be set to shared preferences
	 * @return
	 */
	public boolean isSharedSessionIdWillBeUpdated() {
		return sharedSessionIdWillBeUpdated;
	}

	/**
	 * if true session id which gathered after web service call, will be set to shared preferences
	 * @param sharedSessionIdWillBeUpdated
	 */
	public void setSharedSessionIdWillBeUpdated(boolean sharedSessionIdWillBeUpdated) {
		this.sharedSessionIdWillBeUpdated = sharedSessionIdWillBeUpdated;
	}

	public ILoginRequestHandler getHandler() {
		return handler;
	}
	public void setHandler(ILoginRequestHandler handler) {
		this.handler = handler;
	}
	public String getServerUrl() {
		return serverUrl;
	}
	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	
}
